package com.example.mq.consumer;

import cn.hutool.json.JSONUtil;
import com.example.dto.TransferMsg;
import com.example.mq.dto.Msg;
import com.example.service.AccountService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/*
@description:
@ClassName TransferMsgConsumer
@author chen
@create 2025-08-26 11:04
@Version 1.0
*/
@Component
@Slf4j
public class TransferMsgConsumer extends AbstractIdempotentConsumer<TransferMsg, Msg<TransferMsg>>
{

    @Autowired
    private AccountService accountService;
    @RabbitListener(queues = "transferQueue")
    public void dispose(Message message)
    {
        super.dispose(message);
    }


    @Override
    protected void disposeIn(Message message, TransferMsg body)
    {
        log.info("处理转账消息：{}", JSONUtil.toJsonStr(body));

        this.accountService.balanceAdd(body.getToAccountId(),body.getTransferPrice());
    }
}
